package com.evolved.automata.android.bots.speechbot;
import java.util.Hashtable;
import java.util.Comparator;
import java.util.LinkedList;

public class StackComparator<String> implements Comparator<String>
{
	java.lang.String[] sortPreferenceOrder;
	
	boolean ascendingP;
	public StackComparator(java.lang.String[] sortPreferenceOrder, boolean ascendingP)
	{
		this.ascendingP = ascendingP;
		this.sortPreferenceOrder=sortPreferenceOrder;
	}
	
	public StackComparator(LinkedList<java.lang.String> ssortPreferenceOrder, boolean ascendingP)
	{
		this.ascendingP = ascendingP;
		this.sortPreferenceOrder=ssortPreferenceOrder.toArray(new java.lang.String[0]);
		
	}
	
	
	public int compare(String lValue, String rValue)
	{
		Hashtable<java.lang.String,java.lang.String> lValueMap= StandardTools.parseToKeyValueMap((java.lang.String)lValue);
		Hashtable<java.lang.String,java.lang.String> rValueMap = StandardTools.parseToKeyValueMap((java.lang.String)rValue);
		
		int compare=0;
		for (java.lang.String sortKey:sortPreferenceOrder)
		{
			if (lValueMap.containsKey(sortKey)&&rValueMap.containsKey(sortKey))
			{
				compare=StandardTools.doLogicalStringComparison((java.lang.String)lValueMap.get(sortKey), (java.lang.String)rValueMap.get(sortKey));
				
				if (compare!=0)
					return compare * ((ascendingP)?(1):(-1));
			}
		}
		
		return 0;
	}
	
	
	
	public boolean equals(Object o)
	{
		return false;
	}
	
	
}
